//
//  DRCube.m
//  opengl_practice
//
//  Created by 3irobot2020 on 2022/4/11.
//

#import "DRCube.h"

//定义顶点坐标
const static RWTVertex vertices[] = {
    //front
    {{1, -1, 1}, {1, 0 , 0, 1}},    // 0
    {{1, 1, 1}, {1, 0 , 0, 1}},     // 1
    {{-1, 1, 1}, {0, 1 , 0, 1}},    // 2
    {{-1, -1, 1}, {0, 0 , 1, 1}},   // 3
    
    //back
    {{-1, -1, -1}, {1, 0 , 0, 1}},  // 4
    {{-1, 1, -1}, {1, 0 , 0, 1}},   // 5
    {{1, 1, -1}, {0, 1 , 0, 1}},    // 6
    {{1, -1, -1}, {0, 0 , 1, 1}}   // 7
};

const static GLubyte indices[] = {
    // Front
    0, 1, 2,
    2, 3, 0,
    // Back
    4, 5, 6,
    6, 7, 4,
    // Left
    3, 2, 5,
    5, 4, 3,
    // Right
    7, 6, 1,
    1, 0, 7,
    // Top
    1, 6, 5,
    5, 2, 1,
    // Bottom
    3, 4, 7,
    7, 0 ,3
};
@implementation DRCube
-(instancetype)initWithShader:(RWTBaseEffect *)shader{
    if (self = [super initWithName:"cube" shader:shader vertices:(RWTVertex*)vertices vertexCount:sizeof(vertices)/sizeof(vertices[0]) indices:(GLubyte *)indices indexCount:sizeof(indices)/sizeof(indices[0])]){
        
    }
    
    return self;
}

-(void)updateWithDelta:(NSTimeInterval)dt{
    //按照时间进行绕Y、Z轴旋转
    self.rotationY += M_PI * dt;
    self.rotationZ += M_PI * dt;
}
@end
